package processes.jurassicPark;

import os.MiniSemaphore;

public class GiftShop
{

	private MiniSemaphore countingSimaphore;
	private static GiftShop instance;
	private int capacity;

	public static GiftShop getInstance(int capacity)
	{
		if (instance == null)
			instance = new GiftShop(capacity);
		return instance;
	}

	private GiftShop(int capacity)
	{
		this.setCapacity(capacity);
		countingSimaphore = new MiniSemaphore(capacity);
	}

	public void shop(PassengerThread passanger)
	{
		countingSimaphore.P();
		System.err.println("passenger no " + passanger.getPassengerNum()
				+ " is now shopping");
		passanger.shopping();
		countingSimaphore.V();

	}

	public void setCapacity(int capacity)
	{
		this.capacity = capacity;
	}

	public int getCapacity()
	{
		return capacity;
	}

}
